package org.xdq.demo.base;

/**
 * 标准的响应结果封装类
 */
public class Result {

    public static final int CODE_OK = 200;
    public static final int CODE_ERR_BUSINESS = 500;
    public static final int CODE_ERR_UNLOGINED = 520;
    public static final int CODE_ERR_SYS = 530;

    public static Result OK(){
        return new Result(true,CODE_OK,null,null);
    }
    public static Result OK(String message){
        return new Result(true,CODE_OK,message,null);
    }

    public static Result OK(Object data){
        return new Result(true,CODE_OK,null,data);
    }

    public static Result OK(String message,Object data){
        return new Result(true,CODE_OK,message,data);
    }

    public static Result err(int errCode,String message){
        return new Result(false,errCode,message,null);
    }

    public static Result err(int errCode,String message,Object data){
        return new Result(false,errCode,message,data);
    }


    private boolean success;//是否成功
    private int code;//自定义业务代码，200：成功，500：业务失败，520：用户未登录，530：系统错误
    private String message;//概述信息
    private Object data;//数据

    private Result(boolean success,int code,String messaage,Object data){
        this.success = success;
        this.code = code;
        this.message = messaage;
        this.data =data;
    }

    public boolean isSuccess() {
        return success;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Object getData() {
        return data;
    }
}
